import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { STColumn, STPage, STColumnTag } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { HttpService, SupDic, GridComponent } from 'lbf';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
import { LbRepComponent } from '@shared/components/lb-rep/lb-rep.component';

@Component({
  selector: 'app-zwybpub-sxjd',
  templateUrl: './sxjd.component.html',
})
export class ZwybpubSxjdComponent implements OnInit {
  @ViewChild('st', { static: true }) st: GridComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;

  dataset = [];
  PROJID = '';
  DAD069 = '';

  tabMode = '';

  isVisible = false;

  print_data = [];

  params = {
    sname: 'Sxjd_tysl',
    form: {},
  };

  TAG: STColumnTag = {
    0: { text: '不通过', color: 'red' },
    1: { text: '通过', color: 'green' },
  };

  searchSchema: SFSchema = {
    properties: {
      AAA027: {
        type: 'string',
        title: '统筹区',
        enum: this.supdic.getSFDic('AAA027'),
        ui: {
          widget: 'select',
          allowClear: true,
          grid: { span: 6 },
        },
      },
      SDATE: {
        type: 'string',
        title: '开始时间起',
        ui: { widget: 'date' },
      },
      EDATE: {
        type: 'string',
        title: '开始时间止',
        ui: { widget: 'date' },
      },
      DAD024: {
        type: 'string',
        title: '环节名称',
        enum: this.supdic.getSFDic('DAD024'),
        ui: { widget: 'select', allowClear: true, grid: { span: 6 } },
      },
      DAD017: {
        type: 'string',
        title: '主事项名称',
        enum: this.supdic.getSFDic('DAD017'),
        ui: {
          widget: 'select',
          allowClear: true,
        },
      },
      DAD075: {
        type: 'string',
        title: '申请人姓名',
        grid: { span: 6 },
      },
      PROJID: {
        type: 'string',
        title: '办件编码',
      },
    },
    ui: {
      spanLabelFixed: 100,
      grid: {
        span: 8,
      },
    },
  };

  columns: STColumn[] = [
    {
      title: '主事项名称',
      index: 'DAD017',
      dic: 'DAD017',
      width: '100px',
      fixed: 'left',
    },
    { title: '环节', index: 'DAD024', dic: 'DAD024' },
    // { title: '子事项名称', index: 'DAD031' },
    //  { title: '子环节', index: 'DAD090', dic: 'DAD090' },
    { title: '环节状态', index: 'DAD095', type: 'tag', tag: this.TAG },
    { title: '申请者名称', index: 'DAD075' },
    { title: '申请证件号码', index: 'DAD070', dic: 'DAD070' },
    { title: '申请证件类型', index: 'DAD074', dic: 'DAD074' },
    { title: '来源', index: 'DAD072', dic: 'DAD072' },
    //{ title: '申请方类型', index: 'DAD036', dic: 'DAD036', width: '70px' },
    { title: '统筹区', index: 'AAA027', dic: 'AAA027' },
    { title: '办件编码', index: 'PROJID' },
    { title: '联系人姓名', index: 'DAD113' },
    //{ title: '联系证件号码', index: 'DAD114' },
    // { title: '联系证件类型', index: 'DAD116', dic: 'DAD074' },
    { title: '联系手机号码', index: 'DAD115' },
    { title: '不予受理原因', index: 'DAD098' },
    { title: '开始时间', index: 'DAD096' },
    { title: '结束时间', index: 'DAD097' },
    {
      title: '操作区',
      width: '100px',
      fixed: 'right',
      buttons: [
        {
          text: '查看',
          click: (record: any) => this.queryMX(record),
        },
      ],
    },
  ];

  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    {
      title: '操作区',
      buttons: [
        {
          text: '打开',
          click: (record: any) => this.open(record),
        },
      ],
    },
    /*{ title: '材料数量', index: 'STUFFNUM', width: '25%' },
    
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },*/
  ];

  print_columns: STColumn[] = [
    { title: '打印单名称', index: 'REPNAME' },
    {
      title: '操作区',
      fixed: 'right',
      buttons: [
        {
          text: '打印',
          click: (record: any) => this.reprint(record),
        },
      ],
    },
  ];

  page: STPage = {
    show: false,
  };

  constructor(
    private supdic: SupDic,
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private modalService: NzModalService,
  ) {}

  ngOnInit() {}

  queryMX(record: any) {
    this.PROJID = record.PROJID;
    this.DAD069 = record.DAD069;
    this.YBCL_QUERY();
    this.REPRINT_QUERY();
    //this.tabMode = 'show';
    this.isVisible = true;
  }

  reprint(record: any) {
    const modal = this.modalService.create({
      nzTitle: '打印',
      nzContent: LbRepComponent,
      nzComponentParams: {
        repid: record.REPID,
        inpara: { DAD069: this.DAD069 },
      },
      nzWidth: 880,
    });
  }

  //材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCLSM_QUERY', {
        para: { PROJID: this.PROJID, FLAG: '2' },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }

  //打印列表
  REPRINT_QUERY() {
    this.lbservice
      .lbservice('query_reprint', {
        para: { DAD069: this.DAD069 },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.print_data = resdata.message.list;
        }
      });
  }

  selectTab() {
    this.tabMode = 'show';
  }

  handleCancel() {
    this.tabMode = '';
    this.isVisible = false;
  }

  _onReuseInit(): void {
    this.query();
  }

  query() {
    this.st.reload(this.sf.value);
  }

  reset() {
    this.sf.formData = null;
    this.sf.reset();
  }

  open(recode: any) {
    if(recode.ATTACHPATH!=="无"){
      window.open(recode.ATTACHPATH);
    }else{
      alert("不存在文件地址");
    }

  }
}
